var snowCount=20;
var snowSpeed=30;
var x=new Array(snowCount);
var y=new Array(snowCount);
var n=new Array(snowCount);
var rx=new Array(snowCount);
var ry=new Array(snowCount);

var ww=170;
var hh=84;
var i,xn,yn;

document.write('<div id="snow_div">');
for (i=0; i<snowCount; i++) {
  document.write('<div class="snowball" id="snowball'+i+'"></div>')
  makeNewSnawball(i);
  y[i]=Math.random()*(hh-15);
  $('#snowball'+i).css( {'left': ''+x[i]+'px',
                         'top': ''+y[i]+'px',
                         'background': 'url(/img/snowball'+(i%3)+'.png)'
                         
  } ); 
}  
document.write('</div>')
animateSnow();

//-----------------------------------
function makeNewSnawball(ind) {
  x[ind]=ww-(ww-65)*Math.random()-50;
  y[ind]=-5;
  n[ind]=Math.random()*180;
  ry[ind]=Math.random()+0.5;
  rx[ind]=Math.random()*2;
}
//-----------------------------------
function animateSnow () {
  for (i=0; i<snowCount; i++) {
    xn=rx[i]*Math.cos(n[i]*Math.PI/180.0);
    x[i]=x[i]-xn-1;
    y[i]=y[i]+ry[i];
    if (y[i]>67) makeNewSnawball(i);
    n[i]=n[i]+5;
    if (n[i]>=360) n[i]=n[i]-360;
    $('#snowball'+i).css({'left': ''+x[i]+'px', 'top' : ''+y[i]+'px'});
  }     
  setTimeout("animateSnow()",snowSpeed);
}
//-----------------------------------